package logic

import (
	"context"
	"mycrm/mycrmrpc/mycrmrpc"

	"mycrm/api/internal/svc"
	"mycrm/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CaptchaLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CaptchaLogic {
	return &CaptchaLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CaptchaLogic) Captcha(req *types.CaptchaRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	captcha, err := l.svcCtx.MycrmRpc.Captcha(l.ctx, &mycrmrpc.CaptchaRequest{
		Account: req.Account,
		Source:  req.Source,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "图形验证码发送成功",
		Code:    200,
		Data:    captcha,
	}, nil
}
